#!/usr/bin/env python2.5

## Merges all of my Python files onto the Tutor.

import sys, re

tutor = open(sys.argv[1], 'r')
for line in tutor:
	if re.match("if \(__name__ == \"__main__\"\)", line):
		break
	print line[:-1]
for py in sys.argv[2:]:
	try:
		prog = open(py, 'r')
	except:
		continue
	print "\n## Code immigrated from module", py + "."
	for line2 in prog:
		if not (re.match('import', line2) or re.match('from', line2) or re.match('if \(__', line2) or re.match('#\!', line2)):
			print "\t" + line2[:-1]
		if re.match('if \(__name', line2):	break
	prog.close()
	print
# main = False
print line[:-1]
for line in tutor:
	# if re.match("if \(__name__ == \"__main__\"\)", line):	main = True
	# if main:
	print line[:-1]
tutor.close()
